/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package edu.pdx.cs.guavadata.condition;

import edu.pdx.cs.guavadata.data.Common;
import edu.pdx.cs.guavadata.domain.Domain;
import edu.pdx.cs.guavadata.subclass.ConditionType;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.UUID;

/**
 *
 * @author VuTran
 */
public class GTCond extends Condition {

    private Object arg;

    public GTCond(List<Object> args) throws ConditionException {
        if (args.size() != getNumArgs())
            throw new ConditionException("You have specified the wrong number of conditions (" + args.size() + ") for an equality predicate.", getNumArgs());
        arg = args.get(0);
    }

    @Override
    public String toString() {
        return ">" + Common.wrap(arg);
    }

    @Override
    public ConditionType getCondType() {
        return ConditionType.GT;
    }

    @Override
    public final int getNumArgs() {
        return 1;
    }

    @Override
    public List<Object> getArgs() {
        List<Object> lo = new ArrayList<Object>(getNumArgs());
        lo.add(arg);
        return lo;
    }

    @Override
    public boolean equals(Object obj) {
        return ((obj instanceof GTCond) && ((GTCond) obj).arg.equals(arg));
    }

    @Override
    public int hashCode() {
        return this.getClass().hashCode() +  arg.hashCode();
    }

    @Override
    public boolean getNeedsOrdered() {
        return true;
    }

    @Override
    public boolean getNeedsContain() {
        return false;
    }

    @Override
    public boolean Validate(Object obj, Domain d) {
        if (d.toString().equals("TinyInteger")) {
            return ((Byte) obj) > ((Byte) arg);
        } else if (d.toString().equals("SmallInteger")) {
            return ((Short) obj) > ((Short) arg);
        } else if (d.toString().equals("Integer")) {
            return ((Integer) obj) > ((Integer) arg);
        } else if (d.toString().equals("BigInteger")) {
            return ((Long) obj) > ((Long) arg);
        } else if (d.toString().equals("String")) {
            return ((String) obj).compareTo((String) arg) > 0;
        } else if (d.toString().equals("Numeric")) {
            return ((BigDecimal) obj).compareTo((BigDecimal) arg) > 0;
        } else if (d.toString().equals("DateTime")) {
            return ((Date) obj).compareTo((Date) arg) > 0;
        } else {
            return false;
        }
    }

}
